//
//  NetworkManager.m
//  JobFree2.0
//
//  Created by Dale on 2017/6/8.
//  Copyright © 2017年 Dale. All rights reserved.
//

#import "NetworkManager.h"
#import "JFScrumModel.h"

@implementation NetworkManager

+ (void)configureNetwork {
    YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
#if kIsOuternet
    config.baseUrl = outernet;
#else
    config.baseUrl = intranet;
#endif
}

@end

static double const timeOutInterval = 15.0;

#pragma mark - -----------用户-------------
//MARK: - 用户登录
@implementation LoginApi{
    id _para;
}

- (instancetype)initWithPara:(id)para {
    self = [super init];
    if (self) {
        _para = para;
    }
    return self;
}
- (NSString *)requestUrl {
    return @"/user/login_wx";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

-(id)requestArgument {
    return _para;
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

@end

//MARK: - 上传Client_id
@implementation UserClientIdApi

- (NSString *)requestUrl {
    return @"/user/client_id";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPUT;
}

-(id)requestArgument {
    return @{@"user_id": [JFUser mainJFUser].user_id,
             @"client_id":jfClientID};
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

@end

//MARK: - 获取与当前用户存在关系的用户
@implementation UserRelatedApi

- (NSString *)requestUrl {
    return @"/user/related";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodGET;
}

-(id)requestArgument {
    return @{@"user_id": [JFUser mainJFUser].user_id};
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

@end

#pragma mark - -----------看板-------------
//MARK: - 获取我的看板
@implementation GetBoardsApi{
    id _para;
}

- (instancetype)initWithPara:(id)para {
    self = [super init];
    if (self) {
        _para = para;
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/board/getBoards";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodGET;
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

- (id)requestArgument {
    return @{@"user_id": [JFUser mainJFUser].user_id,
             @"page":_para};
}

@end

//MARK: - 创建看板
@implementation CreateBoardApi{
    NSString *board_name;
    NSString *board_remark;
    NSString *board_logo;
    NSString *phases;
    NSString *members;
}

- (instancetype)initWithPara:(id)para {
    self = [super init];
    if (self) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:para];
        board_name = dic[@"board_name"];
        board_remark = dic[@"board_remark"];
        board_logo = dic[@"board_logo"];
        phases = dic[@"phases"];
        members = dic[@"members"];
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/board/create";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (id)requestArgument {
    return @{@"board_name":board_name,
             @"board_remark":board_remark,
             @"board_logo":board_logo,
             @"phases":phases,
             @"members":members,
             @"user_id": [JFUser mainJFUser].user_id};
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

@end


//MARK: - 看板详情
@implementation BoardDetailApi

- (NSString *)requestUrl {
    return @"/board/detail";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodGET;
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

@end

//MARK: 看板Notesize
@implementation BoardNotesizeApi{
    NSString *board_id;
    NSString *note_size;
    
}

- (instancetype)initWithPara:(id)para {
    self = [super init];
    if (self) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:para];
        board_id = dic[@"board_id"];
        note_size = dic[@"note_size"];
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/board/noteSize";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPUT;
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

- (id)requestArgument {
    return @{@"board_id":board_id,
             @"note_size":note_size,
             @"user_id": [JFUser mainJFUser].user_id};
}

@end

//MARK: 看板BoardName
@implementation BoardNameApi{
    NSString *board_name;
    NSString *board_id;
}

- (instancetype)initWithPara:(id)para {
    self = [super init];
    if (self) {
        board_name = para[@"board_name"];
        board_id = para[@"board_id"];
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/board/boardName";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPUT;
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

- (id)requestArgument {
    return @{@"board_id":board_id,
             @"board_name":board_name,
             @"user_id": [JFUser mainJFUser].user_id};
}

@end

//MARK: BoardJoin
@implementation BoardJoinApi{
     NSString *board_id;
}

- (instancetype)initWithPara:(id)para {
    self = [super init];
    if (self) {
        board_id = para[@"board_id"];
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/board/join";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

- (id)requestArgument {
    return @{@"board_id":board_id,
             @"user_id": [JFUser mainJFUser].user_id};
}

@end


//MARK: - 看板退出
@implementation BoardExitApi{
    NSString *board_id;
}

- (instancetype)initWithPara:(JFScrumModel *)para {
    self = [super init];
    if (self) {
        board_id = para.board_id;
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/board/exit";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (id)requestArgument {
    return @{@"board_id":board_id,
             @"user_id": [JFUser mainJFUser].user_id};
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

@end

//MARK: 看板解散
@implementation BoardDismissApi{
    NSString *board_id;
}

- (instancetype)initWithPara:(JFScrumModel *)para {
    self = [super init];
    if (self) {
        board_id = para.board_id;
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/board/dismiss";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

- (id)requestArgument {
    return @{@"board_id":board_id,
             @"user_id": [JFUser mainJFUser].user_id};
}

@end

//MARK: 看板置顶
@implementation BoardTopApi{
    NSString *board_id;
    NSNumber *is_top;
}

- (instancetype)initWithPara:(JFScrumModel *)para {
    self = [super init];
    if (self) {
        board_id = para.board_id;
        is_top = @(para.is_top);
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/board/top";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

- (id)requestArgument {
    return @{@"board_id":board_id,
             @"is_top":is_top,
             @"user_id": [JFUser mainJFUser].user_id};
}

@end

//MARK: 看板免打扰
@implementation BoardDisturbApi{
    NSString *board_id;
    NSNumber *is_disturb;
}

- (instancetype)initWithPara:(JFScrumModel *)para {
    self = [super init];
    if (self) {
        board_id = para.board_id;
        is_disturb = @(para.is_disturb);
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/board/disturb";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

- (id)requestArgument {
    return @{@"board_id":board_id,
             @"is_disturb":is_disturb,
             @"user_id": [JFUser mainJFUser].user_id};
}

@end

#pragma mark - -----------任务-------------
//MARK: 得到任务
@implementation GetTasksApi

- (NSString *)requestUrl {
    return @"/task/getTasks";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodGET;
}

- (NSTimeInterval)requestTimeoutInterval {
    return timeOutInterval;
}

@end











